//
//  LGBloodGlucoseCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/6.
//

#import "LGBloodGlucoseCell.h"

#define dateWidth    viewPix(53)
#define itemHeight   viewPix(32)
#define itemWidth    (Screen_W-viewPix(32)-dateWidth)/4.0

@interface LGBloodGlucoseCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UILabel *itemLabel1;
/**   */
@property (nonatomic , strong)UILabel *itemLabel2;
/**   */
@property (nonatomic , strong)UILabel *itemLabel3;
/**   */
@property (nonatomic , strong)UILabel *itemLabel4;
/**   */
@property (nonatomic , strong)UIView *topLine;
/**   */
@property (nonatomic , strong)UIView *vertLine1;
/**   */
@property (nonatomic , strong)UIView *vertLine2;
/**   */
@property (nonatomic , strong)UIView *vertLine3;
/**   */
@property (nonatomic , strong)UIView *vertLine4;
/**   */
@property (nonatomic , strong)NSDictionary *colorDic;

@end

@implementation LGBloodGlucoseCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
        self.colorDic = @{@"0":@"#333333",@"1":@"#E53C39",@"2":@"#FF9704"};
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.dateLabel.text = dataDic[@"record_date"];
    //早餐前-空腹
    self.itemLabel1.text = dataDic[@"a_fbg"];
    self.itemLabel1.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"a_fbg_status"])]];
    //早饭后
    self.itemLabel2.text = dataDic[@"a_pbg"];
    self.itemLabel2.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"a_pbg_status"])]];
    //午饭前
    self.itemLabel3.text = dataDic[@"b_pbg"];
    self.itemLabel3.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"b_pbg_status"])]];
    //午饭后
    self.itemLabel4.text = dataDic[@"c_pbg"];
    self.itemLabel4.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"c_pbg_status"])]];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.topLine];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.vertLine1];
    [self.baseView addSubview:self.itemLabel1];
    [self.baseView addSubview:self.vertLine2];
    [self.baseView addSubview:self.itemLabel2];
    [self.baseView addSubview:self.vertLine3];
    [self.baseView addSubview:self.itemLabel3];
    [self.baseView addSubview:self.vertLine4];
    [self.baseView addSubview:self.itemLabel4];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _baseView.frame = CGRectMake(viewPix(16), -viewPix(10), Screen_W-viewPix(32), itemHeight+viewPix(20));
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIView *)topLine{
    if(!_topLine){
        _topLine = [[UIView alloc]initWithFrame:CGRectMake(0, viewPix(10), Screen_W-viewPix(32), 1)];
        _topLine.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _topLine;
}


-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
        _dateLabel.frame = CGRectMake(0, kMaxY(self.topLine.frame), dateWidth, itemHeight);
    }
    return _dateLabel;
}


-(UILabel *)itemLabel1{
    if(!_itemLabel1){
        _itemLabel1 = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _itemLabel1.frame = CGRectMake(kMaxX(self.vertLine1.frame), kMaxY(self.topLine.frame), itemWidth-1, itemHeight);
    }
    return _itemLabel1;
}

-(UILabel *)itemLabel2{
    if(!_itemLabel2){
        _itemLabel2 = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _itemLabel2.frame = CGRectMake(kMaxX(self.vertLine2.frame), kMaxY(self.topLine.frame), itemWidth-1, itemHeight);
    }
    return _itemLabel2;
}


-(UILabel *)itemLabel3{
    if(!_itemLabel3){
        _itemLabel3 = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _itemLabel3.frame = CGRectMake(kMaxX(self.vertLine3.frame), kMaxY(self.topLine.frame), itemWidth-1, itemHeight);
    }
    return _itemLabel3;
}


-(UILabel *)itemLabel4{
    if(!_itemLabel4){
        _itemLabel4 = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _itemLabel4.frame = CGRectMake(kMaxX(self.vertLine4.frame), kMaxY(self.topLine.frame), itemWidth-1, itemHeight);
    }
    return _itemLabel4;
}



-(UIView *)vertLine1{
    if(!_vertLine1){
        _vertLine1 = [[UIView alloc]initWithFrame:CGRectMake(kMaxX(self.dateLabel.frame), 0, 1, viewPix(20)+itemHeight)];
        _vertLine1.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _vertLine1;
}

-(UIView *)vertLine2{
    if(!_vertLine2){
        _vertLine2 = [[UIView alloc]initWithFrame:CGRectMake(kMaxX(self.itemLabel1.frame), 0, 1, viewPix(20)+itemHeight)];
        _vertLine2.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _vertLine2;
}

-(UIView *)vertLine3{
    if(!_vertLine3){
        _vertLine3 = [[UIView alloc]initWithFrame:CGRectMake(kMaxX(self.itemLabel2.frame), 0, 1, viewPix(20)+itemHeight)];
        _vertLine3.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _vertLine3;
}

-(UIView *)vertLine4{
    if(!_vertLine4){
        _vertLine4 = [[UIView alloc]initWithFrame:CGRectMake(kMaxX(self.itemLabel3.frame), 0, 1, viewPix(20)+itemHeight)];
        _vertLine4.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _vertLine4;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
